﻿using Basic.FlowGatewayModule.Interface;
using Basic.FlowGatewayModule.Model;
using Basic.FlowRemoteModel.Application;
using Basic.FlowRemoteModel.Application.Model;
using Basic.FlowRemoteModel.AuditSignFile;
using Basic.FlowRemoteModel.AuditSignFile.Model;
using WeDonekRpc.Client;
using WeDonekRpc.Modular;

namespace Basic.FlowGatewayModule.lmpl
{
    internal class FlowAuditSignFileService : IFlowAuditSignFileService
    {
        public void AddSignLog ( AuditSignAdd data, long empId )
        {
            AuditSignFileLog log = data.ConvertMap<AuditSignAdd, AuditSignFileLog>();
            log.SignEmpId = empId;
            new AddAuditSignLog
            {
                Data = log
            }.Send();
        }
        public long Add ( SignFileAdd add, long empId )
        {
            return new AddAuditSignFile
            {
                Datum = new AuditSignFileAdd
                {
                    EmpId = empId,
                    FileId = add.FileId,
                    FileName = Path.GetFileNameWithoutExtension(add.FileName),
                    FileUri = add.FileUri,
                    FormFileId = add.FormFileId,
                    ItemId = add.ItemId,
                    LogId = add.LogId
                }
            }.Send();
        }
        public void SetImgUri ( long id, SignImg obj )
        {
            new SetAuditSignFileImg
            {
                Id = id,
                FileId = obj.FileId,
                ImgUri = obj.FileUri,
            }.Send();
        }

        public void Delete ( long id )
        {
            new DeleteAuditSignFile
            {
                Id = id
            }.Send();
        }

        public AuditSignFile[] Gets ( long logId )
        {
            return new GetAuditSignFiles
            {
                LogId = logId
            }.Send();
        }
        public void Accredit ( long logId, long fileId, IUserState state )
        {
            new ApplySignFileAccredit
            {
                Accredit = new SignFileAccredit
                {
                    AccreditId = state.AccreditId,
                    EmpId = state.ToEmpId(),
                    FileId = fileId,
                    LogId = logId
                }
            }.Send();
        }
    }
}
